<template>
  <HomePanel title="人气推荐" sub-title="人气爆款 不容错过" ref="target">
    <!-- 数据时 -->
    <ul class="goods-list" v-if="hotData.length">
      <li v-for="item in hotData" :key="item.id">
        <RouterLink to="/">
          <img :src="item.picture" alt="" />
          <p class="name">{{ item.title }}</p>
          <p class="desc">{{ item.alt }}</p>
        </RouterLink>
      </li>
    </ul>
    <!-- 没有数据时 -->
    <transition name="fade">
      <HomeSkeleton v-if="hotData.length === 0" />
    </transition>
  </HomePanel>
</template>

<script>
import HomePanel from "../currency/HomePanel";
import HomeSkeleton from "../currency/HomeSkeleton";
import useLazyData from "../../hooks/useLazyData";
import { getHotPopularity } from "../../api/home";
// import { ref } from "vue";

export default {
  name: "HomeHot",
  components: { HomePanel, HomeSkeleton },
  setup() {
    let { target, result: hotData } = useLazyData(getHotPopularity());

    return {
      target,
      hotData,
    };
  },
};
</script>

<style scoped lang="less">
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 426px;

  li {
    width: 306px;
    height: 406px;
    .hoverShadow();

    img {
      width: 306px;
      height: 306px;
    }

    p {
      font-size: 22px;
      padding-top: 12px;
      text-align: center;
    }

    .desc {
      color: #999;
      font-size: 18px;
    }
  }
}

.home-skeleton {
  top: 115px;
}
</style>
